/**
 * 
 */
package fr.cephb.joperon.core.db;


import java.util.HashSet;
import java.util.Set;

import com.sleepycat.db.DatabaseException;


import fr.cephb.joperon.core.Operon;
import fr.cephb.joperon.core.db.base.BaseEWordsDB;
import fr.cephb.joperon.core.entities.EWords;
import fr.cephb.util.CloseableIterator;
import fr.cephb.util.Pair;

/**
 * @author lindenb
 *
 */
public class EWordsDB extends BaseEWordsDB {

	/**
	 * @param operon
	 */
	public EWordsDB(Operon operon) {
		super(operon);
	}

	
	public Set<Integer> getTermIds(String key) throws DatabaseException
		{
		CloseableIterator<EWords> iter=null;
		HashSet<Integer> set= new HashSet<Integer>();
		try {
			iter= listValues(key);
			while(iter.hasNext())
				{
				set.add(iter.next().getTid());
				}
		} catch (DatabaseException e) {
			throw e;
			}
		finally
			{
			if(iter!=null) iter.close();
			}
		
		return set;
		}

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		try {
			Operon op = Operon.newInstance();
			EWordsDB db= new EWordsDB(op);
			db.open();
			int i=0;
			EWordsDB.KeyValueIterator iter=db.listKeyValues();
			while(iter.hasNext())
				{
				Pair<String,EWords> p=iter.next();
				//if(p.first().length()==0) continue;
				System.err.println("["+p.first()+"] "+p.second());
				if(++i==500) break;
				}
			iter.close();
			
			db.close();
			op.close();
		} catch (Exception e) {
		e.printStackTrace();
		}
		
	
	}

}
